import units from '@/assets/scripts/units.js'
const dataInterface={
	baseURL:'',
	globalData:{
		
	},
	chatList:function(data,callback){
		var defaultOption={
			memId:'',
			lastTime:''
		};
		var sendData=this._getParams(data,defaultOption);
		units.AJAX.JsonData('get', this.baseURL+'httpChat/chatList',sendData, (res) => {
			if(typeof callback == 'function'){
				callback(res)
			}
		});
	},
	chatMsgList:function(data,callback){
		var defaultOption={
			memId:'',
			chatId:''
		};
		var sendData=this._getParams(data,defaultOption);
		units.AJAX.JsonData('get', this.baseURL+'httpChat/chatMsgList',sendData, (res) => {
			if(typeof callback == 'function'){
				callback(res)
			}
		});
	},
	chatMsgListSimple:function(data,callback){
		var defaultOption={
			sortId:'',
			chatId:''
		};
		var sendData=this._getParams(data,defaultOption);
		units.AJAX.JsonData('get', this.baseURL+'httpChat/chatMsgListSimple',sendData, (res) => {
			if(typeof callback == 'function'){
				callback(res)
			}
		});
	},
	createChat:function(data,callback){
		var defaultOption={
			accountID:'',
			chatType: '',
			title: '',
			mem: '',
			desc: '',
			approval:'',
			allowInvites:'',
			avatar:'',
			creator:'',
			createTime:'',
			updateTime:''
		};
		var sendData=this._getParams(data,defaultOption);
		units.AJAX.JsonData('POST', this.baseURL+'httpChat/createChat',sendData, (res) => {
			if(typeof callback == 'function'){
				callback(res)
			}
		});
	},
	searchAccountMem:function(data,callback){
		var defaultOption={
			name:'',
		};
		var sendData=this._getParams(data,defaultOption);
		units.AJAX.JsonData('get', this.baseURL+'httpChat/searchAccountMem',sendData, (res) => {
			if(typeof callback == 'function'){
				callback(res)
			}
		});
	},
	_getParams:function(params,defaultOption) {
		/* TODO 私有方法 不能直接调用 */
		var _self =this;
		var tempParams=new Object();
		if(params!=undefined){
			for(var key in defaultOption){
				tempParams[key]=params[key]==undefined?defaultOption[key]:params[key];
				for(var globalDataItem in _self.globalData){
					if(globalDataItem==key.toUpperCase()){
						tempParams[key]= _self.globalData[globalDataItem];
					};
				};
			};
		}else{
			tempParams=defaultOption;
		};	
		return tempParams;
	}
}

export default dataInterface;